home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Apps / Apps.major.cgi.z / Apps.major.cgi
Encoding:
Text File  |  1997-07-30  |  6.0 KB  |  200 lines

  1. #!/usr/bin/perl5
  2.  
  3. # Apps.major.cgi
  4. # Silicon Graphics
  5.  
  6. require "/usr/OnRamp/lib/OnRamp.pm";
  7. require "/usr/OnRamp/lib/java.pm";
  8.  
  9. $myname = "Apps.major.cgi";
  10. $base_url = $ENV{'SERVER_URL'} . "/apps/major-info.cgi";
  11. $major_dir = "$document_root/apps/majordomo";
  12. $list_base = "/usr/freeware/lib/majordomo/lists";
  13. $title = "Majordomo Mailing Lists";
  14. $aliases = "/etc/aliases";
  15.  
  16. opendir(DIR, "$major_dir");
  17. @lists = grep(!/^\.\.?$/, readdir(DIR));
  18. closedir(DIR);
  19. @lists = sort(@lists);
  20.  
  21. &get_fields;
  22.  
  23. $js = "
  24. $js_error_box
  25. which = \"none\";
  26. function runSubmit() {
  27.     form = document.Form;
  28.     if (which == \"sub\" || which == \"uns\") {
  29.         if (form.email.value == \"\") {
  30.             errorBox(form.email, \"Email address required.\");
  31.             return (false);
  32.         } 
  33.         if (form.s_list.value == \"\") {
  34.             errorBox(form.s_list, \"List name required.\");
  35.             return (false);
  36.         }
  37.     }
  38.     if (which == \"loc\") {
  39.         if (form.email.value == \"\") {
  40.             errorBox(form.email, \"Email address required.\");
  41.             return (false);
  42.         }
  43.     }
  44.     if (which == \"search\") {
  45.         if (form.srch.value == \"\") {
  46.             errorBox(form.srch, \"Search string required.\");
  47.             return (false);
  48.         }
  49.     }
  50.     return (true);
  51. }
  52. function markSub() { which = \"sub\"; }
  53. function markUns() { which = \"uns\"; }
  54. function markLocate() { which = \"loc\"; }
  55. function markSearch() { which = \"search\"; }
  56. ";
  57.  
  58. if ($fld{'Search'}) {
  59.     if ($fld{'srch'} eq "") { $message .= "Empty search string."; }
  60.     else {
  61.         $srch = $fld{'srch'};
  62.         @found = grep(/$srch/, @lists);
  63.         if ($#found == -1) { $message .= "No mailing lists found in search."; }
  64.         else { @found = sort(@found); }
  65.     }
  66. } elsif ($fld{'locate'}) {
  67.     $email = $fld{'email'};
  68.     foreach $list (@lists) {
  69.         $file = $list_base . "/" . $list;
  70.         open(IN, "< $file");
  71.         while(<IN>) {
  72.             chop $_;
  73.             if ($email eq $_) { push(@subsc, $list); }
  74.         }
  75.         close(IN);
  76.     }
  77. } elsif ($fld{'subscribe'} || $fld{'unsub'}) {
  78.     if ($fld{'subscribe'}) { $body = "subscribe"; }
  79.     else { $body = "unsubscribe"; }
  80.     $body .= " $fld{'s_list'}";
  81.     $cmd = "echo \"$body\" | /usr/lib/sendmail -f$fld{'email'} majordomo@" . $ENV{'SERVER_NAME'};
  82.     `$cmd > /dev/null 2>&1`;
  83.  
  84.     if ($fld{'subscribe'}) { $message .= "$fld{'email'} subscribed to $fld{'s_list'}.<br>"; }
  85.     else { $message .= "$fld{'email'} removed from $fld{'s_list'}.<br>"; }
  86. }
  87.  
  88. if (! -e "/usr/freeware/lib/majordomo-1.94.1/majordomo") {
  89.     print "Content-type: text/html\n\n";
  90.         print "<h2>Majordomo software not installed.</h2>"
  91.                 . "Majordomo is free software availale as an inst image "
  92.                 . "for your SGI server "           
  93.                 . "(fw_majordomo).  To configure and "
  94.                 . "administer majordomo through Internet Gateway, the "
  95.                 . "majordomo software must be installed from this image. ";
  96.         exit(0);
  97. }
  98.  
  99. &generic;
  100.  
  101. sub generic {
  102.     print "Content-type: text/html\n\n";
  103.     
  104.     &js_title_block("Majordomo", $js);
  105.  
  106.     print "<body bgcolor=#FFFFFF>\n";
  107.  
  108.     print "<i>$message</i>\n";
  109.  
  110.         open(IN, "< $aliases");
  111.         while(<IN>) {
  112.                 if ($_ =~ /^owner-(.*):\s+(.*)/) {
  113.                         $owner{$1} = $2;
  114.                 }
  115.         }
  116.         close(IN);
  117.  
  118.     print "<table width=100%>",
  119.         "<tr><th align=left><h2>$title</h2></th>\n",
  120.         "<th align=right><a href=\"/newsplash.shtml\">",
  121.         "<img height=55 width=57 border=0 src=/apps/home.gif></a>\n",
  122.         "  <a href=\"Apps.shtml\">",
  123.         "<img height=55 width=57 border=0 src=/apps/back.gif></a>",
  124.         "</tr></table><br><br>\n";
  125.  
  126.     print "<form name=Form method=post action=$myname onSubmit=\"return runSubmit()\">\n";
  127.     print "<font size=5><b><tt>Subscription:</tt></b></font><br>\n";
  128.     print "<center><table width=80%><tr align=left><th width=30%>Email address:<td width=20%>", 
  129.         &text("email", "", 15), "</td>\n"
  130.         . "<td width=20%><input type=\"submit\" onClick=\"markSub()\" name=\"subscribe\" value=\"  Subscribe  \"></td></tr>";
  131.     print "<tr><th align=left width=30%>Mailing list:<td width=20%>",
  132.         &text("s_list", "", 15), "</td>\n"
  133.         . "<td width=20%><input type=\"submit\" onClick=\"markUns()\" name=\"unsub\" value=\"Unsubscribe\"></td></tr>\n";
  134.     print "<tr><th align=left colspan=2 width=50%>Locate mailing lists currently subscribed to:\n"
  135.         . "<td width=20%><input type=\"submit\" onClick=\"markLocate()\" name=\"locate\" value=\"    Search     \"></td></tr>\n";
  136.     print "</table></center>";
  137.  
  138.     if ($fld{'locate'}) {
  139.         if ($#subsc == -1) { print "<i>$email is not subscribed to any "
  140.                     . "mailing lists on this server.</i><br>\n"; }
  141.         else { 
  142.             print "<i>$email is currently subscribed to:</i><ul>\n";
  143.             foreach (@subsc) {
  144.                 $url = $base_url . "?$_:$owner{$_}";
  145.                 print "<li><a href=$url>$_</a>\n";
  146.             }
  147.             print "</ul>\n";
  148.         }
  149.         print "<br>\n";            
  150.     }
  151.  
  152.     print "<hr><br>\n";
  153.  
  154.     print "<font size=5><b><tt>Mailing lists:</tt></b></font><br>\n";
  155.  
  156.     print "<center><table width=80%><tr><th align=left width=30%>Keyword search mailing list titles:<td width=20%>\n",
  157.         &text("srch", "", 15), "</td><td width=20%>"
  158.         . "<input type=\"submit\" onClick=\"markSearch()\" name=\"Search\" value=\"    Search     \">\n"
  159.         . "</td></tr></table></center>\n";
  160.     print "</form>";
  161.  
  162.     if ($#found >= 0) {
  163.         print "<i>Found in search:</i>\n";
  164.         print "<ul>\n";
  165.         foreach (@found) {
  166.             $url = $base_url . "?$_:$owner{$_}";
  167.             print "<li><a href=$url>$_</a>\n";
  168.         }
  169.         print "</ul>\n";
  170.     }
  171.  
  172.     print "<ul>\n";
  173.  
  174.     $third = ($#lists + 1)/3;
  175.     if ($third =~ /([0-9]+)\./) { $third = $1; }
  176.     $rem = ($#lists + 1) % 3;
  177.     if ($rem == 0) { $a = $third; $b = $third; $c = $third; }
  178.     elsif ($rem == 1) { $a = $third+1; $b = $third; $c = $third; }
  179.     else { $a = $third+1; $b = $third+1; $c = $third; }
  180.     
  181.     print "<table><tr><td valign=top><ul>";
  182.     for ($i=0; $i<$a; $i++) {
  183.         $url = $base_url . "?$lists[$i]:$owner{$lists[$i]}";
  184.         print "<li><a href=$url>$lists[$i]</a>\n";
  185.     }
  186.     print "</ul></td><td valign=top><ul>\n";
  187.     for ($i=$a; $i<$a+$b; $i++) {
  188.         $url = $base_url . "?$lists[$i]:$owner{$lists[$i]}";
  189.         print "<li><a href=$url>$lists[$i]</a>\n";
  190.     }
  191.     print "</ul></td><td valign=top><ul>\n";
  192.     for ($i=$a+$b; $i<=$#lists; $i++) {
  193.         $url = $base_url . "?$lists[$i]:$owner{$lists[$i]}";
  194.         print "<li><a href=$url>$lists[$i]</a>\n";
  195.     }
  196.     print "</ul></td></tr></table>\n";
  197.  
  198.     print "</body></html>\n";
  199. }
  200.